/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.chart.gdp;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import twaver.Element;
import twaver.TWaverConst;
import twaver.table.TElementTable;

public class MoneyRenderer extends DefaultTableCellRenderer {
	
    public MoneyRenderer(){
    	this.setHorizontalAlignment(SwingConstants.RIGHT);
    	this.setOpaque(true);
    }
    
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
    	String text = null;
    	if(value instanceof Number){
    		text = TWaverConst.DEFAULT_INT_FORMATER.format(((Number)value).doubleValue());
    	}
    	Component comp = super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
    	TElementTable elementTable = (TElementTable)table;
    	Element element = elementTable.getElementByRowIndex(row);
    	comp.setForeground(Color.WHITE);
    	if(!isSelected){
    		comp.setBackground(element.getChartColor());
    	}
    	return comp;
    }
}